package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.entity.union.honors.eHonorsActivityType;
import com.yanqu.road.server.manager.activity.peakseacraft.PeakSeacraftMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.CrossGeneralActivityRankMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.manager.union.honors.CrossUnionHonorsActivityMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_CROSS_GENERAL_ACTIVITY_GET_RANK_REWARD, desc = "跨服领取商会排行奖励")
public class CrossGeneralActivityGetUnionRankRewardCmd extends CrossCommand {

    private int activityId;
    private int conditionType;
    private int conditionId;
    private String unionUid;
    private long userId;
    private int position;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossActivityProto.CrossGeneralActivityGetRewardReqMsg reqMsg = CrossActivityProto.CrossGeneralActivityGetRewardReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionType = reqMsg.getConditionType();
        conditionId = reqMsg.getConditionId();
        unionUid = reqMsg.getUnionUid();
        userId = packet.getPlayerId();
        position = reqMsg.getPosition();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        int rank = CrossGeneralActivityRankMgr.getCrossActivityUnionRank(activityId, conditionType, serverId, unionUid);
        CrossActivityProto.CrossGeneralActivityGetRewardRespMsg.Builder respMsg = CrossActivityProto.CrossGeneralActivityGetRewardRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        respMsg.setConditionType(conditionType);
        respMsg.setConditionId(conditionId);
        respMsg.setRank(rank);
        respMsg.setPosition(position);
        respMsg.setUnionUid(unionUid);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_GENERAL_ACTIVITY_GET_UNION_RANK_REWARD_NOTIFY, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);

        //荣誉点奖励 //荣誉点又变成道具了，领奖加了
        /*ActivityInfo activityInfo = ActivityMgr.getActivityInfo(activityId);
        if(activityInfo != null) {
            boolean isUnionRankType = ActivityHelper.isUnionRankType(conditionType);
            //海上争霸取第二阶段第一名，过滤掉第一阶段榜单
            if(isUnionRankType && conditionType != eGamePlayerEventType.SeacraftPirateRiotUnionScoreRank.getValue()) {
                //获取可获得奖励的最低排名
                if(null == eHonorsActivityType.getHonorsType(activityInfo.getType(),activityInfo.getChildType())){
                    log.info("getHonorsType error,type:{},childType:{}", activityInfo.getType(), activityInfo.getChildType());
                    return;
                }

                int lowestRank = CrossUnionHonorsActivityMgr.getLowestRewardRank(activityInfo.getServerIdList().size(), eHonorsActivityType.getHonorsType(activityInfo.getType(),activityInfo.getChildType()));//取不同荣誉点类型
                List<String> unionUidTop = CrossGeneralActivityRankMgr.getCrossActivityTopUnions(activityId, conditionType, lowestRank);
                CrossUserMgr.getLogger().debug("----  reward serverId {}", serverId);
                CrossUnionHonorsActivityMgr.add(activityId, unionUidTop, activityInfo.getType(), activityInfo.getChildType(), activityInfo.getServerIdList(),serverId);
            }
        }*/
    }

    @Override
    public void sendData() {

    }
}
